package com.forgenet.game.config;

import com.sparrow.common.EnableSparrowCommon;
import com.sparrow.common.perf.PerfTimerManager;
import com.sparrow.common.util.PropertiesUtil;
import com.sparrow.common.uuid.TimeUUIDGenerator;
import com.sparrow.event.EnableSparrowEvent;
import com.sparrow.mongo.EnableSparrowMongo;
import com.sparrow.redis.EnableSparrowRedis;
import com.sparrow.rpc.EnableSparrowRpc;
import com.sparrow.rpc.manager.DistributeConsulRpcNodeManager;
import com.sparrow.servicemgr.consul.ConsulManager;
import com.sparrow.socket.http.EnableSparrowHttp;
import com.sparrow.socket.manager.PacketHandlerManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableSparrowCommon
@EnableSparrowHttp
@EnableSparrowRpc
@EnableSparrowEvent
@EnableSparrowMongo
@EnableSparrowRedis
@ComponentScan({
        "com.forgenet.game",
        "com.forgenet.rpc"
})
public class GameConfig {

    @Bean
    public ConsulManager consulManager() {
        ConsulManager consulManager = new ConsulManager();
        String groupName = PropertiesUtil.getProperty("rpc.node.group");
        String id = PropertiesUtil.getProperty("rpc.node.id");
        String ip = PropertiesUtil.getProperty("rpc.node.ip");
        int port = PropertiesUtil.getPropertyAsInt("rpc.node.port");
        consulManager.register(groupName, id, ip, port);
        return consulManager;
    }

    @Bean
    public DistributeConsulRpcNodeManager nodeMgr() {
        return new DistributeConsulRpcNodeManager();
    }

    @Bean
    public PerfTimerManager perfTimerRegistry() {
        return new PerfTimerManager();
    }

    @Bean
    public TimeUUIDGenerator idGenerator() {
        return new TimeUUIDGenerator(1);
    }


    @Bean
    public PacketHandlerManager packetHandlerManager() {
        return new PacketHandlerManager();
    }
}
